package com.kll.carolinehmibiz

import android.content.Context
import com.kll.carolinehmibiz.model.AccountModel
import com.kll.carolinehmibiz.net.bean.LoginResponse

/**
 * ====================================================
 * Created by Ziliang Cai on 2021/12/06 21:21
 * <a href="mailto:752577456@qq.com">Contact me</a>
 * ====================================================
 */
class AccountManager {

    private lateinit var mContext: Context

    companion object {

        private var mInstance: AccountManager? = null

        @Synchronized
        fun getInstancce(): AccountManager {
            if(mInstance == null) {
                mInstance = AccountManager()
            }
            return mInstance!!
        }
    }

    fun init(context: Context) {
        mContext = context.applicationContext
    }

    /**
     * 获取用户信息
     */
    fun getLoginUserInfo(): LoginResponse.UserInfo? {
        return AccountModel.getInstance(mContext).getUserInfo()
    }

    /**
     * 获取用户token
     */
    fun getLoginUserToken(): LoginResponse.UserToken? {
        return AccountModel.getInstance(mContext).getUserToken()
    }

    /**
     * 获取所有账号列表
     */
    fun getAllAccount(): ArrayList<LoginResponse> {
        return AccountModel.getInstance(mContext).getAllAccounts()
    }

    /**
     * 删除指定账号
     * @param mobile 手机号
     */
    fun removeAccount(mobile: String) {
        AccountModel.getInstance(mContext).removeAccount(mobile)
    }

    /**
     * 删除当前账号
     */
    fun removeCurrentAccount() {
        var account = AccountModel.getInstance(mContext).getUserInfo()
        if(account != null) {
            AccountModel.getInstance(mContext).removeAccount(account.mobile)
        }
    }

    /**
     * 切换登录账号
     * @param mobile 手机号
     */
    fun switchLoginAccount(mobile: String) {
        AccountModel.getInstance(mContext).switchAccount(mobile)
    }

    fun getUserSig(): String? {
        return AccountModel.getInstance(mContext).getUserSig()
    }

    fun getSdkAppId(): String? {
        return AccountModel.getInstance(mContext).getSdkAppId()
    }

    fun get(){
        AccountModel.getInstance(mContext).getUserSig()
    }
}